import torch

data = torch.tensor([[10, 20, 30], [40, 50, 60]])
# 1.使用shape属性或者size方法都可以获得张量的形状
print(data.shape)
print(data.size)
# 2.使用reshape函数修改张量形状
new_data = data.reshape(1, 6)
print(new_data.shape)



# todo 示例
# 创建一个一维张量
tensor_1d = torch.tensor([1, 2, 3, 4, 5, 6])
print("原始一维张量:")
print(tensor_1d)

# 将一维张量转换为二维张量，形状为 (2, 3)
tensor_2d_1 = tensor_1d.reshape(2, 3)
print("\n转换为 (2, 3) 形状的二维张量:")
print(tensor_2d_1)

# 将一维张量转换为二维张量，形状为 (3, 2)
tensor_2d_2 = tensor_1d.reshape(3, 2)
print("\n转换为 (3, 2) 形状的二维张量:")
print(tensor_2d_2)

# 创建一个二维张量
tensor_2d = torch.tensor([[1, 2, 3], [4, 5, 6]])
print("\n原始二维张量:")
print(tensor_2d)

# 将二维张量转换为一维张量
tensor_1d_new = tensor_2d.reshape(-1)
print("\n转换为一维张量:")
print(tensor_1d_new)